package com.ebeijia.controller;

import com.ebeijia.context.RequestResponseContext;
import com.ebeijia.mybatis.pojo.ComplaintSuggInfo;
import com.ebeijia.query.Paginator;
import com.ebeijia.query.SuggInfoQuery;
import com.ebeijia.service.admin.ComplaintSuggInfoService;
import com.ebeijia.web.ResponseMessage;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

/**
 * Created by YPJ on 2016/5/17.
 */
@Controller
@RequestMapping("/comp")
public class CompSuggController {
    @Resource
    private ComplaintSuggInfoService complaintSuggInfoService;

    @RequestMapping("/toSuggList.htm")
    public ModelAndView toList() {
        ModelAndView modelAndView = new ModelAndView("work/comPlainList");
        return modelAndView;
    }

    @RequestMapping("/suggList.json")
    @ResponseBody
    public ResponseMessage suggList(SuggInfoQuery suggInfoQuery) {
        if(suggInfoQuery.getBusiType().equals("请选择")){
            suggInfoQuery.setBusiType(null);
        }
        Paginator<ComplaintSuggInfo> paginator =
            new Paginator<ComplaintSuggInfo>(suggInfoQuery, complaintSuggInfoService.queryProSuggest(suggInfoQuery),
                complaintSuggInfoService.queryProSuggestCount(suggInfoQuery));
        return  ResponseMessage.success(paginator);
    }
    @RequestMapping("/applyCom.json")
    @ResponseBody
    public ResponseMessage applyCom(ComplaintSuggInfo complaintSuggInfo){
        if(StringUtils.isBlank(complaintSuggInfo.getReplyContent())){
            return  ResponseMessage.error("201","回复内容不能为空");
        }
       int temp = complaintSuggInfoService.applyCom(complaintSuggInfo);
        if(temp>0){
            return  ResponseMessage.success();
        }
        return ResponseMessage.error();
    }

}
